package com.gl.codewar.template;

import java.util.Arrays;

public class DivideBy11 {

	public static boolean isDivideBy11(long i) {
		
		String number = String.valueOf(i);
		Long remainer = convert(number);
		return remainer >= 11 && (remainer % 11 == 0);
	}
	
	private static Long convert(String lala) {
		if (lala.length() <= 2) {
			return Long.parseLong(lala);
		} else {
			char[] array = lala.toCharArray();
			Integer last = Integer.parseInt(String.valueOf(array[array.length - 1]));
			
			char [] remainer = Arrays.copyOfRange(array, 0, array.length - 1);
			Long longRem = Long.parseLong(String.valueOf(remainer));
			Long remMinus = longRem - last;
			return convert(String.valueOf(remMinus));
		}
	}  

}
